package com.macro.mall.controller;

import com.macro.mall.annotationUtil.CurrentUserName;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.UmsAdminDTO;
import com.macro.mall.model.*;
import com.macro.mall.service.UmsAdminService;
import com.macro.mall.wms.dto.WmsCheckStorageDto;
import com.macro.mall.wms.dto.WmsInventoryListParam;
import com.macro.mall.wms.service.IInventoryService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 盘点管理
 *
 * @author 孙晓亮
 * @Date 2020年9月14日
 */


@Controller
@RequestMapping("/wmsInventory")
@ResponseBody
public class WmsInventoryStorageController {

    @Autowired
    IInventoryService iInventoryService;
    @Autowired
    private UmsAdminService umsAdminService;


    /**
     * 获取盘点商品列表
     * @author 孙晓亮
     * @Date 2020年9月14日
     * @param currentUserName
     * @param wmsCheckStorageDto
     * @return
     */
    @ApiModelProperty("获取盘点商品列表")
    @RequestMapping(value = "/getInventoryProductList" ,method = RequestMethod.POST)
    public CommonResult<CommonPage<CheckStorageVo>> getCheckProductList(@CurrentUserName String currentUserName,@RequestBody WmsCheckStorageDto wmsCheckStorageDto){

        UmsAdmin admin = this.umsAdminService.getAdminByUsername(currentUserName);
        List<CheckStorageVo> checkStorageVoList = iInventoryService.getCheckProductList(admin,currentUserName,wmsCheckStorageDto);
        CommonPage<CheckStorageVo> checkStorageVoListCommonPage = CommonPage.restPage(checkStorageVoList);
        return  CommonResult.success(checkStorageVoListCommonPage);
    }

    @ApiModelProperty("查询库存列表")
    @RequestMapping(value = "/getStockList",method = RequestMethod.POST)
    public CommonResult<CommonPage<CheckStorageVo>> getStockList(@CurrentUserName String currentUserName,@RequestBody WmsCheckStorageDto wmsCheckStorageDto){
        UmsAdmin admin = this.umsAdminService.getAdminByUsername(currentUserName);
        List<CheckStorageVo> checkStorageVoList = iInventoryService.getStockList(admin,currentUserName,wmsCheckStorageDto);
        CommonPage<CheckStorageVo> checkStorageVoListCommonPage = CommonPage.restPage(checkStorageVoList);
        return  CommonResult.success(checkStorageVoListCommonPage);
    }

    /**
     * 生成盘点单
     * @author 孙晓亮
     * @Date 2020年9月14日
     * @param wmsCreateCheckStorageDtoList
     * @return
     */
    @ApiModelProperty("生成盘点单")
    @RequestMapping(value = "/createInventory",method = RequestMethod.POST)
    public CommonResult createCheck(@CurrentUserName String currentUserName,@RequestBody List<WmsCreateCheckStorageDto> wmsCreateCheckStorageDtoList){
        UmsAdmin admin = this.umsAdminService.getAdminByUsername(currentUserName);
        UmsAdminDTO adminDTO = this.umsAdminService.getAdminDTOByUserName(currentUserName);
        return iInventoryService.createCheck(admin,wmsCreateCheckStorageDtoList,adminDTO.getStoreId());
    }

    /**
     * 查询盘点单商品
     * @return
     */
    @ApiModelProperty("查询盘点单商品")
    @RequestMapping(value = "/getInventoryStorageItems",method = RequestMethod.GET)
    public CommonResult<List<WmsInventoryStorageItemDTO>> getInventoryStorageItems(@RequestParam Long id){
        return iInventoryService.getInventoryStorageItems(id);
    }

    /**
     * 查询全部盘点单
     * @param wmsInventoryListParam
     * @return
     */
    @ApiModelProperty("查询盘点单")
    @RequestMapping(value ="/getInventoryList",method = RequestMethod.POST)
    public CommonResult getInventoryList(@RequestBody WmsInventoryListParam wmsInventoryListParam){

       //List<InVentoryStorageDto> inVentoryStorageDtoList= ;
        return CommonResult.success(iInventoryService.getInventoryList(wmsInventoryListParam));
    }
}
